package cn.zjjd.wlproject.hhx.demo.controller;

import cn.zjjd.wlproject.hhx.demo.config.PwdMD5;
import cn.zjjd.wlproject.hhx.demo.pojo.Admin;
import cn.zjjd.wlproject.hhx.demo.service.AdminService;
import cn.zjjd.wlproject.hhx.demo.util.GeneralResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
public class AdminController {
    @Autowired
    private AdminService adminService;
    private PwdMD5 pwdMD5;

    @RequestMapping("/signing")
    public String addAdmin(@RequestParam String username, @RequestParam String password,HttpServletRequest request){
        Admin admin = new Admin();
        admin.setUsername(username);
        admin.setPassword(pwdMD5.MD5(password));
        admin.setRightgrade(2);
        int state = adminService.addAdmin(admin);
        if(state == 1){
            request.setAttribute("state","注册成功");
            return "login";
        }
        else {
            request.setAttribute("state","注册失败");
            return "signup";
        }
    }
}
